import React, { Component } from 'react';
import axios from 'axios';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  constructor(props){
    super(props);
    this.state = {
      userInfo:{}
    }
  }
  componentDidMount() {
    this.getAllUser();
  }

  getAllUser() {
    const that = this;

    axios.get('/api/getAllUser').then((res) =>{
            const users = res.data;
            if(res.status === 200){
              console.log(users)
              that.setState({users})  
            }
        }).catch((err) =>{
            console.log(err);
        })

    // fetch('/api/getAllUser',{credentials: 'include'})
    //   .then( (res) => {
    //     console.log(res)
    //     return res.json();
    //   })
    //   .then( (res) => {
    //     console.log(res)
    //   })
    //   .catch( (err) => {
    //     console.log(err)
    //   })

/*var newItem = {
  name:"小明",
  age:24,
  sex:"man"
};
      axios.post('/api/addUser',{
            newItem
        }).then((res) => {
            console.log("添加成功");
            const todoList = res.data;
            console.log(todoList)
            that.setState({
                todoList
            })
        }).catch((err) => {
            console.log(err);

        })*/

  }
  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">Welcome to React</h1>
        </header>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;
